import {
	mapState,
	mapMutations
} from "vuex"
import {
	queryAddressBookList,
	updateAddressBookDefault
} from "./api.js"
export default {
	data() {
		return {
			addressList: [],
			
		}
	},
	onShow() {
		this.onShowCall();
	},
	onLoad(options) {

	},
	computed:{
		
	},
	methods: {
		// 编辑地址, 跳转到editAdress页面了, 可以使用uni.setStorageSync、Vuex、globalData 、query 
		editAddress(item){
			uni.navigateTo({
				url: "/pages/address/addAddress/index?addressId="+item.id,
			})
		},
		addNewAddressFromWX(){
			uni.showToast({
				title: '为了信息安全，暂不支持从微信导入地址！',
				icon: "none",
				duration: 1000,
			});
		},
		addNewAddress(){
			uni.navigateTo({
				url: "/pages/address/addAddress/index",
			})
		},
		goBack() {
			uni.navigateBack({ delta: 1 })
		},
		// 修改默认的地址
		changeDefaultAddress(item){
			updateAddressBookDefault(item).then((res) =>{
				if(res.code === 200){
					this.onShowCall();
				}else{
					uni.showToast({
						title: '操作失败',
						icon: "fail",
						duration: 1000,
					});
				}
			}).catch((error) =>{})
		},
		onShowCall(){
			queryAddressBookList().then((res) =>{
				this.addressList = res.data;
			}).catch((error) =>{})
		},
		//   vuex储存信息
		...mapMutations([
			"setShopInfo", //设置店铺信息
			"setShopPhone", //设置电话
			"setShopStatus", //设置店铺状态
			"initdishListMut", //设置购物车订单
			"setStoreInfo",
			"setBaseUserInfo", //设置用户基本信息
			"setLodding",
			"setToken", //设置token
			"setDeliveryFee", //设置配送费
		]),
		// 从vuex信息
		...mapState([
			"shopInfo", //店铺信息
			"shopPhone", //电话
			"orderListData",
			"baseUserInfo", //用户信息
			"lodding",
			"token", //token
			"deliveryFee", //配送费
		]),
		
		
	}

}